package com.cat.chapter047;
import java.util.Arrays;

/**
 * @author cat
 * @description https://leetcode.cn/problems/corporate-flight-bookings/
 * @create 2025/7/16 10:42
 * @since JDK17
 */

public class Solution01 {
    static int MAXN = 20010;
    static int[] diff = new int[MAXN];
    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] ans = new int[n];
        Arrays.fill(diff, 0);
        int m = bookings.length, sum = 0;
        for (int i = 0; i < m; i++) {
            diff[bookings[i][0] - 1] += bookings[i][2];
            diff[bookings[i][1]] -= bookings[i][2];
        }
        for (int i = 0; i < n; i++) {
            sum += diff[i];
            ans[i] = sum;
        }
        return ans;
    }
}